﻿Namespace Utilities


    'TODO: Get unit tests set up for the unit converter
    Module UnitConverter



#Region "Enums"



        Public Enum DigitalStorageUnits
            BYTE_UNIT = 1
            KILOBYTE_UNIT = 1024
            MEGABYTE_UNIT = 1048576
            GIGABYTE_UNIT = 1073741824
        End Enum



#End Region



#Region "Public Functions"



        Public Function ConvertBetweenDigitalStorageUnits(ByVal unitFrom As DigitalStorageUnits, _
                                                          ByVal valueFrom As Decimal, _
                                                          ByVal unitTo As DigitalStorageUnits) As Decimal

            'TODO: Comment this function so its clear on its behaviour

            Dim convertedValue As Decimal = Decimal.MinValue


            Select Case unitFrom


                Case DigitalStorageUnits.BYTE_UNIT

                    convertedValue = convertFromBytes(valueFrom, _
                                                      unitTo)


                Case Else




            End Select


            Return convertedValue


        End Function



#End Region



#Region "Private Functions"



        Private Function convertFromBytes(ByVal valueFrom As Decimal, _
                                          ByVal unitTo As DigitalStorageUnits) As Decimal


            Dim convertedValue As Decimal = Decimal.MinValue


            Try

                convertedValue = valueFrom / CInt(unitTo)

            Catch ex As Exception

                'TODO: Log conversion error

            End Try


            Return convertedValue


        End Function



#End Region



    End Module



End Namespace